fix(parser): handle heredoc pipe ordering and edge cases#379
Merged
Conversation
bcfc0fd to
d50c0cf
Compare
- Lexer saves rest-of-line after heredoc delimiter and re-injects it via a VecDeque buffer, so `cat <<EOF | sort` correctly pipes heredoc content - Pipe continuation (`cat <<EOF |\nsort`) also works via the same mechanism - Quote-aware rest-of-line scanning handles `cat <<EOF; echo "two\nthree"` where double-quoted strings span physical lines - read_continuation_into concatenates adjacent quoted/unquoted segments after single-quoted strings, enabling partial-quote delimiters like `<<'EOF'"2"` -> delimiter `EOF2` - Multiple heredocs on one line work naturally via repeated rest-of-line save/reinject (e.g., `while cat <<E1 && cat <<E2; do ... done`) - While/until condition stdout is now captured and emitted, fixing `while cat <<EOF; do ... done` producing no condition output Enables all 6 previously-skipped heredoc-edge spec tests. Closes #359
d50c0cf to
7acf973
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cat <<EOF | sortnow correctly pipes heredoc content to the next command in the pipelinecat <<EOF |\nsortworks via rest-of-line re-injection<<'EOF'"2"correctly combines to delimiterEOF2with quoting preventing expansionwhile cat <<E1 && cat <<E2; do ... doneparses and executes correctlycat <<EOF; echo "two\nthree"handles quoted strings spanning linesAll 6 previously-skipped heredoc-edge spec tests are now enabled and passing.
Approach
Lexer: Added a
VecDeque<char>re-injection buffer.read_heredocsaves the rest of the command line (after the heredoc delimiter token) instead of discarding it, then re-injects it after reading the heredoc body.peek_char/advancecheck the buffer first.Lexer:
read_continuation_intoconcatenates adjacent quoted/unquoted segments after a single-quoted string, enabling partial-quote heredoc delimiters.Interpreter:
execute_whileandexecute_untilnow capture and emit condition command stdout/stderr.Test plan
cargo fmt --checkcleanresolve_redirect_urldead_code only)Closes #359